from rest_framework.response import Response


class ApiResponse(Response):

    def __init__(self, code=None, message="ok", data=None, status=200, total=None,
                 template_name=None, headers=None, exception=False, content_type='application/json'):
        super(Response, self).__init__(None, status=status)
        code = code or 200
        self.data = {"code": code, "message": message, "data": data}
        if total:
            self.data.update({'total': total})
        self.template_name = template_name
        self.exception = exception
        self.content_type = content_type

        if headers:
            for name, value in headers.items():
                self[name] = value


